<?php

/**
 * Framework_Presenter_Smarty_DebugOutput
 *
 * @author Application Support Group
 * @copyright University of Georgia
 * @license http://www.opensource.org/licenses/gpl-license.php
 * @package BAMF
 * @filesource
*/


/**
 * Framework_Presenter_Smarty_DebugOutput
 *
 *
 * @author Application Support Group
 * @package BAMF
 * @link http://smarty.php.net
*/
class Framework_Presenter_Smarty_DebugOutput extends Framework_Presenter_Smarty_Extension {

	public function __construct() {
		parent::__construct() ;
	}

	public static function register( &$smartyObj ) {
		$smartyExtension = new Framework_Presenter_Smarty_DebugOutput() ;
		$smartyObj->register_function( "debugOutput", array( $smartyExtension, "outputDebugCode" )) ;
	}

	/** output standard debugging information about the incoming data */
	public function outputDebugCode( $params ) {

		$_output = array() ;
		$outputArray = array(
			"_REQUEST" => $_REQUEST,
			"_GET" => $_GET,
			"_POST" => $_POST,
			"_SESSION" => $_SESSION,
			"_COOKIE" => $_COOKIE
		) ;
		
		if ( SHOW_DEBUG_SERVER ) {
			$outputArray[ "_SERVER" ] = $_SERVER ;
		}
		if ( SHOW_DEBUG_ENV ) {
			$outputArray[ "_ENV" ] = $_ENV ;
		}
		
	
	
		$_output[] = "<div id='debug' class='showdebug'>" ;
		$_output[] = "<div id='debugctl'>" ;
		$_output[] = "<a class='debugctl' onclick='document.getElementById( \"debug\" ).className=\"hidedebug\"'>X</a>" ;
		$_output[] = "</div>" ;
	
		
		foreach ( $outputArray as $key => $val ) {
			$_output[] = "<p><span class='dbHeader'>[$key]</span><br /><blockquote>" ;
			$_output[] = $this->debugSection( $val ) ;	
			$_output[] = "</blockquote></p>" ;
		}
	
		$_output[] = "<div>" ;
		$_output[] = "<span class='dbKey'>BAMF.php</span> = <span class='dbValue'>" . BAMF_FILE . "</span>" ;
		$_output[] = "</div>" ;
		$_output[] = "</div>" ;
	
		return implode( "\n", $_output ) ;
	}
	
	
	private function debugSection( $thisArray ) {
		$_output = array() ;
		foreach( $thisArray as $thisKey => $thisVal ) {
			if ( is_array( $thisVal )) {
				$_output[] = "<span class='dbArray'>$thisKey</span> :: <ul>" ;
				foreach( $thisVal as $thisSubkey => $thisSubval ) {
					$_output[] = "<li><span class='dbKey'>$thisSubkey</span> = <span class='dbValue'>$thisSubval</span></li>" ;
				}
				$_output[] = "</ul>" ;
			} else {
				$_output[] = "<span class='dbKey'>$thisKey</span> :: <span class='dbValue'>" ;
				if( $thisKey == "password" ) {
					$_output[] = preg_replace( "/./", "*", $thisVal ) ;
				} else {
					$_output[] = $thisVal ;
				}
				$_output[] = "</span><br />" ;
			}
		}
	
	
		return implode( "\n", $_output ) ;
	
	}


	public function __destruct() {}


}
